package com.example.asus.yuejian_10.fragment;


import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.example.asus.yuejian_10.R;
import com.example.asus.yuejian_10.adapter.ActivityAdapter;
import com.example.asus.yuejian_10.bean.ListResult_1;
import com.example.asus.yuejian_10.imple.Home_actimple;
import com.example.asus.yuejian_10.model.Model;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;

/**
 * A simple {@link Fragment} subclass.
 */
public class ActivityFragment extends Fragment {
    private View view;
    private RecyclerView recyclerView;
    private List<ListResult_1> list;
    private Context context;
    private ActivityAdapter activityadapter;


    public ActivityFragment() {
        // Required empty public constructor
    }



    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view = inflater.inflate(R.layout.fragment_activity, container, false);
        inte();
        event();
        return view ;
    }
    public void inte()
    {
        context=getActivity();
        recyclerView= (RecyclerView)view.findViewById(R.id.actlist1);
    }
    public void event()
    {
        Retrofit retrofit= Model.getConn();
        Home_actimple home_actimple=retrofit.create(Home_actimple.class);
        Call<List<ListResult_1>> call= home_actimple.getActList();
        call.enqueue(new Callback<List<ListResult_1>>() {
            @Override
            public void onResponse(Call<List<ListResult_1>> call, Response<List<ListResult_1>> response) {
                list = response.body();
                ActivityAdapter activityAdapter = new ActivityAdapter(context, list);
                LinearLayoutManager manager = new LinearLayoutManager(context);
                manager.setOrientation(LinearLayoutManager.VERTICAL);
                recyclerView.setLayoutManager(manager);
                recyclerView.setAdapter(activityAdapter);
                recyclerView.setItemAnimator(new DefaultItemAnimator());
            }


            @Override
            public void onFailure(Call call, Throwable t) {
                Toast.makeText(context,"列表获取失败",Toast.LENGTH_SHORT).show();

            }
        });

    }


}
